package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.BusinessCategory;
import cn.stylefeng.guns.modular.system.service.IBusinessCategoryService;

/**
 * 服务大类控制器
 *
 * @author fengshuonan
 * @Date 2019-10-23 16:49:47
 */
@Controller
@RequestMapping("/businessCategory")
public class BusinessCategoryController extends BaseController {

    private String PREFIX = "/system/businessCategory/";

    @Autowired
    private IBusinessCategoryService businessCategoryService;

    /**
     * 跳转到服务大类首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "businessCategory.html";
    }

    /**
     * 跳转到添加服务大类
     */
    @RequestMapping("/businessCategory_add")
    public String businessCategoryAdd() {
        return PREFIX + "businessCategory_add.html";
    }

    /**
     * 跳转到修改服务大类
     */
    @RequestMapping("/businessCategory_update/{businessCategoryId}")
    public String businessCategoryUpdate(@PathVariable Integer businessCategoryId, Model model) {
        BusinessCategory businessCategory = businessCategoryService.selectById(businessCategoryId);
        model.addAttribute("item",businessCategory);
        LogObjectHolder.me().set(businessCategory);
        return PREFIX + "businessCategory_edit.html";
    }

    /**
     * 获取服务大类列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return businessCategoryService.selectList(null);
    }

    /**
     * 新增服务大类
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BusinessCategory businessCategory) {
        businessCategoryService.insert(businessCategory);
        return SUCCESS_TIP;
    }

    /**
     * 删除服务大类
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer businessCategoryId) {
        businessCategoryService.deleteById(businessCategoryId);
        return SUCCESS_TIP;
    }

    /**
     * 修改服务大类
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BusinessCategory businessCategory) {
        businessCategoryService.updateById(businessCategory);
        return SUCCESS_TIP;
    }

    /**
     * 服务大类详情
     */
    @RequestMapping(value = "/detail/{businessCategoryId}")
    @ResponseBody
    public Object detail(@PathVariable("businessCategoryId") Integer businessCategoryId) {
        return businessCategoryService.selectById(businessCategoryId);
    }
}
